<?php
$exmatid = $_POST['exmatid'];
require('../../cofd/common.php');
$stmt = $conn->prepare("SELECT * FROM exam_page WHERE exmatid = ?");
if ($stmt === false) {
    echo json_encode(array('status' => 500, 'msg' => '准备查询失败: ' . $mysqli->error));
    exit();
}
$stmt->bind_param('s', $exmatid); 
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $getresult = $row['exmatzt'];
    }
} else {
    echo json_encode(array('status' => 500, 'msg' => $conn));
    exit();
}
$newStatus = ($getresult == 1) ? 0 : 1;
$stmt = $conn->prepare("UPDATE exam_page SET exmatzt = ? WHERE exmatid = ?");
$stmt->bind_param('is', $newStatus, $exmatid); 
if ($stmt->execute()) {
    echo json_encode(array('status' => 200, 'msg' => '操作成功'));
} else {
    echo json_encode(array('status' => 400, 'msg' => '操作失败'));
}
$stmt->close();
$conn->close();
?>